<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/16
 * Time: 23:34
 */

namespace app\admin\controller;


class Link extends common
{
    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new \app\common\model\Link();
    }
    //主页
    public function index(){
        $data=db('link')->select();
        $this->assign('data',$data);
        //视图
        return view();
    }
    //添加
    public function add(){
        if(request()->isPost()){
            $data=input('post.');
            $res=$this->db->add($data);
            if($res['valid']){
                $this->success($res['msg'],'index');
            }else{
                $this->error($res['msg']);
            }
        }
        //视图
        return view();
    }
    //编辑
    public function edit(){
        //分配数据
        $lid = input('param.lid');
        $oldData = db('link')->find($lid);
        $this->assign('oldData',$oldData);
        if(request()->isPost()) {
            $data = input('post.');
            $res = $this->db->edit($data);
            if ($res['valid']) {
                $this->success($res['msg'], 'index');
            } else {
                $this->error($res['msg']);
            }
        }

        //视图
        return view();
    }
    //删除
    public function del(){
        $lid=input('param.lid');
        $res = $this->db->del($lid);
        if ($res['valid']){
            $this->success($res['msg'],'index');
        }else{
            $this->error($res['msg']);
        }

    }
}